{==============================================================================}
{  Acroprise Multi-Language Components                                         }
{                                                                              }
{  Copyright (C), 1999-2012, Acroprise Inc.                                    }
{  http://www.acroprise.com.tw                                                 }
{  ALL RIGHTS RESERVED                                                         }
{                                                                              }
{  Author   : Mustapha.Wang                                                    }
{  Version  : 4.1.14.2158                                                      }
{  Creation : 2002/05/06                                                       }
{  Revision :                                                                  }
{  Task     :                                                                  }
{==============================================================================}
unit acroMultiReg;
{$I acroMultiLang.inc}
interface
uses
  Classes,SysUtils,Windows,
  {$IFNDEF Delphi15High}
  Dialogs,
  {$ELSE}
  vcl.Dialogs,
  {$ENDIF}
  {$IFNDEF Delphi5High}
  DsgnIntf,
  {$ELSE}
  VclEditors,DesignEditors,DesignIntf,
  {$ENDIF}
  TypInfo,ToolsAPI,
  acroMultiDD,acroMultiDDWriter,acroMultiResource,
  acroMultiScreen,acroMultiDDCatcher,acroMultiDesignEditor,
  acroMultiReplacer,acroMultiMessageBox;
type
  TDDReaderIDProperty=class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TDDNameProperty=class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TDictionaryProperty=class(TClassProperty)
  public
    function GetAttributes:TPropertyAttributes;override;
    function GetValue:string;override;
    procedure Edit;override;
  end;

  TDictionaryEditor=class(TComponentEditor)
  protected
    procedure GetPropEdit(const Editor: IProperty);
  public
    function GetVerb(Index:Integer):string;override;
    function GetVerbCount:Integer;override;
    procedure ExecuteVerb(Index:Integer);override;
  end;

  TDDFileNameProperty=class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure Edit; override;
  end;

  procedure Register;
//delphi11,old component icon in *dcr not transparent
//https://blogs.embarcadero.com/new-in-10-2-2-component-icons/
{$R *.dcr}
{$R acroSplash.res}

implementation

{$IFDEF Delphi11High}
//for delphi7,not surport utf8 file formate
uses
  acroMultiReg.str.utf8;

procedure RegisterSplash;
var
  ASplashBitmap: HBITMAP;
begin
  ForceDemandLoadState(dlDisable);
  ASplashBitmap := LoadBitmap(HInstance, 'acroMultiLanguage');
  try
    SplashScreenServices.AddPluginBitmap(
      'Acroprise Multi-Language Suite for Delphi Win32'{$IFDEF Delphi15High}+'/64'{$ENDIF}+', '+GetPackageVersion(),
      ASplashBitmap);
  finally
    DeleteObject(ASplashBitmap);
  end;

end;

var
  FAboutInfoIndex: Integer;
  FAboutBitmap: HBITMAP;

procedure AddAboutInfo;
var
  AServices: IOTAAboutBoxServices;
  ATitle,ADescription: string;
begin
  FAboutInfoIndex := -1;
  if Supports(BorlandIDEServices, IOTAAboutBoxServices, AServices) then
  begin
    ATitle := 'Acroprise Multi-Language Suite for Delphi Win32'{$IFDEF Delphi15High}+'/64'{$ENDIF}+', '+GetPackageVersion();
    ADescription:=s_About_Description;
    FAboutBitmap := LoadBitmap(HInstance, 'acroMultiLanguage');
    FAboutInfoIndex := AServices.AddPluginInfo(ATitle,
      ADescription,
      FAboutBitmap,false,s_About_LicenseStatus,s_About_SKUName);
  end;
end;

procedure RemoveAboutInfo;
var
  AServices: IOTAAboutBoxServices;
begin
  if Supports(BorlandIDEServices, IOTAAboutBoxServices, AServices) and
    (FAboutInfoIndex <> -1) then
  begin
    AServices.RemovePluginInfo(FAboutInfoIndex);
    DeleteObject(FAboutBitmap);
  end;
end;
{$ENDIF}

procedure Register;
begin
  {$IFDEF Delphi11High}
  RegisterSplash;
  {$ENDIF}
  RegisterComponents('acro MultiLang',[TacroMultiFileDD,TacroMultiStreamDD,
    TacroMultiDDEvents,TacroMultiReplacer,TacroMsgBox,TacroMultiScreenEvents,
    TacroMultiResourceEvents,TacroMultiDDKeyCatcher]);
  RegisterPropertyEditor(TypeInfo(TMultiDictionary),nil,'Dictionary',TDictionaryProperty);
  RegisterPropertyEditor(TypeInfo(string),TCustomMultiReaderDD,'DDReaderID',TDDReaderIDProperty);
  RegisterPropertyEditor(TypeInfo(string),TCustomMultiReplaceOption,'DDName',TDDNameProperty);
  RegisterPropertyEditor(TypeInfo(string),TacroMsgBox,'DDName',TDDNameProperty);
  RegisterPropertyEditor(TypeInfo(string),TacroMultiFileDD,'FileName',TDDFileNameProperty);

  RegisterComponentEditor(TacroMultiStreamDD,TDictionaryEditor);
  RegisterComponentEditor(TacroMultiFileDD,TacroComponentEditor);
  RegisterComponentEditor(TacroMultiDDEvents,TacroComponentEditor);
  RegisterComponentEditor(TacroMultiReplacer,TacroComponentEditor);
  RegisterComponentEditor(TacroMsgBox,TacroComponentEditor);
  RegisterComponentEditor(TacroMultiScreenEvents,TacroComponentEditor);
  RegisterComponentEditor(TacroMultiResourceEvents,TacroComponentEditor);
  RegisterComponentEditor(TacroMultiDDKeyCatcher,TacroComponentEditor);
end;

{ TDictionaryEditor }

procedure TDictionaryEditor.ExecuteVerb(Index: Integer);
var
  SD:TSaveDialog;
  List: IDesignerSelections;
  AData:PDDReaderWriterData;
begin
  inherited;
  case Index of
    0:begin
        List := TDesignerSelections.Create;
        try
          List.Add(Component);
          GetComponentProperties(List, [tkClass], Designer, GetPropEdit);
        finally
          List:=nil;
        end;
      end;
    1:begin
        SD:=TSaveDialog.Create(nil);
        try
          SD.FileName:=TacroMultiStreamDD(Component).DDName;
          AData:=DDReaderWriterStorage.GetDDReaderWriterDataByID(TacroMultiStreamDD(Component).DDReaderID);
          if AData<>nil then
            SD.FileName:=SD.FileName+'.'+AData^.Ext
          else if DDReaderWriterStorage.Count>0 then
            SD.FileName:=SD.FileName+'.'+DDReaderWriterStorage.DDReaderWriterData[0]^.Ext;

          if SD.Execute then
          begin
            TacroMultiStreamDD(Component).Dictionary.Stream.SaveToFile(SD.FileName);
          end;
        finally
          SD.Free;
        end;
      end;
    2:begin
        TacroMultiStreamDD(Component).Dictionary.Stream.Clear;
        Designer.Modified;
      end;
  end;
end;

procedure TDictionaryEditor.GetPropEdit(const Editor: IProperty);
begin
  if Editor.GetName='Dictionary' then
    Editor.Edit;
end;

function TDictionaryEditor.GetVerb(Index: Integer): string;
begin
  Result:='';
  case Index of
    0:Result:=S_LoadDic;
    1:Result:=S_SaveDic;
    2:Result:=S_ClearDic;
    3:Result:='-';
    4:Result:=S_ProductName+' '+GetPackageVersion;
  end;
end;

function TDictionaryEditor.GetVerbCount: Integer;
begin
  Result:=5;
end;

{ TDictionaryProperty }

procedure TDictionaryProperty.Edit;
var
  OD:TOpenDialog;
  Description,Filters,vExt:string;
  vData:PDDReaderWriterData;
begin
  OD:=TOpenDialog.Create(nil);
  try
    DDReaderWriterStorage.BuildFilterStrings(nil,Description,Filters);
    OD.Filter:=Description;
    if OD.Execute then
    begin
      TacroMultiStreamDD(GetComponent(0)).Dictionary.Stream.LoadFromFile(OD.FileName);
      vExt:=ExtractFileExt(OD.FileName);
      Delete(vExt,1,1);
      vData:=DDReaderWriterStorage.GetDDReaderWriterDataByFileExt(vExt);
      if vData<>nil then TacroMultiStreamDD(GetComponent(0)).DDReaderID:=vData^.ID;

      Designer.Modified;
    end;
  finally
    OD.Free;
  end;
end;

function TDictionaryProperty.GetAttributes: TPropertyAttributes;
begin
  Result:=[paReadOnly,paDialog];
end;

function TDictionaryProperty.GetValue: string;
begin
  Result:='('+GetPropType^.Name+') Size: '+
    InttoStr(TMultiDictionary(GetOrdValue).Stream.Size);
end;

{ TDDReaderIDProperty }

function TDDReaderIDProperty.GetAttributes: TPropertyAttributes;
begin
  Result:=[paMultiSelect,paValueList,paSortList,paRevertable];
end;

procedure TDDReaderIDProperty.GetValues(Proc: TGetStrProc);
var
  i:integer;
begin
  inherited;
  for i:=0 to DDReaderWriterStorage.Count-1 do
    Proc(DDReaderWriterStorage.DDReaderWriterData[i]^.ID);
end;

{ TDDNameProperty }

function TDDNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result:=[paMultiSelect,paValueList,paSortList,paRevertable];
end;

procedure TDDNameProperty.GetValues(Proc: TGetStrProc);
var
  i:integer;
begin
  inherited;
  for i:=0 to acroDDStorage.DDCount-1 do
    Proc(acroDDStorage.DD[i].DDName);
end;

{ TDDFileNameProperty }

procedure TDDFileNameProperty.Edit;
var
  OD:TOpenDialog;
  Description,Filters:string;
begin
  inherited;
  OD:=TOpenDialog.Create(nil);
  try
    DDReaderWriterStorage.BuildFilterStrings(nil,Description,Filters);
    OD.Filter:=Description;
    OD.FileName:=TacroMultiFileDD(GetComponent(0)).FileName;
    if OD.Execute then
    begin
      TacroMultiFileDD(GetComponent(0)).FileName:=OD.FileName;
      Designer.Modified;
    end;
  finally
    OD.Free;
  end;
end;

function TDDFileNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result:=[paRevertable,paDialog];
end;

initialization
{$IFDEF Delphi11High}
  AddAboutInfo();
{$ENDIF}
finalization
{$IFDEF Delphi11High}
  RemoveAboutInfo();
{$ENDIF}
end.
